#include <stdio.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>


int main(int argc, char *argv[])
{
	int sock_fd = socket(AF_INET,SOCK_DGRAM,0);
	if(sock_fd <0){
		perror("");
	}

	struct sockaddr_in addr;
	addr.sin_family =AF_INET;
	addr.sin_port = htons(50001);
	addr.sin_addr.s_addr =0;
	int ret = bind(sock_fd, (struct sockaddr*)&addr, sizeof(addr));
	if (ret < 0)
	{
		perror("bind error");
	}
	struct sockaddr_in cli_addr;
	socklen_t len = sizeof(cli_addr);
	while(1){
		char buf[128] = "";
		int n=recvfrom(sock_fd, buf, sizeof(buf), 0, (struct sockaddr*)&cli_addr,&len);
		printf("%s\n", buf );
		sendto(sock_fd, buf, n, 0, (struct sockaddr*)&cli_addr, sizeof(cli_addr));
	}
	close(sock_fd);
}